﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RentHouse.DTO;
using RentHouse.IService;
using RentHouse.Service.Entities;
using RentHouse.Common;
namespace RentHouse.Service
{
    public class RegionService : IRegionService
    {
        public List<RegionDTO> GetRegionList(long cityId)
        {
            using (var db=new RentHouseContext())
            {
                var bs = new BaseService<T_Regions>(db);
                var query = PredicateExtensions.True<T_Regions>();
                if (cityId>0)
                {
                    query = query.And(e => e.CityId == cityId);
                }
                var list = bs.GetList(query).Select(e=>new RegionDTO() { 
                    CityId=e.CityId,
                    Id=e.Id,
                    Name=e.Name
                }).ToList();
                return list;
            }
        }
    }
}
